local kl__zhangming = fk.CreateSkill {
  name = "kl__zhangming",
  tags = { Skill.Compulsory },
}

kl__zhangming:addEffect(fk.CardUsing, {
  anim_type = "offensive",
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(kl__zhangming.name) and data.card.color ~= Card.NoColor
  end,
  on_use = function(self, event, target, player, data)
    if data.card.color == Card.Black then
      data.disresponsiveList = table.simpleClone(player.room.players)
    elseif data.card.color == Card.Red then
      data.additionalDamage = (data.additionalDamage or 0) + 1
    end
  end,
})
kl__zhangming:addEffect(fk.Damage, {
  anim_type = "drawcard",
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(kl__zhangming.name) and
      player:usedEffectTimes(self.name) == 0 and player ~= data.to and not data.to.dead
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local types = {"basic", "trick", "equip"}
    if not data.to.dead then
      local cards = table.filter(data.to:getCardIds("h"), function (id)
        return not data.to:prohibitDiscard(id)
      end)
      if #cards > 0 then
        local id = table.random(cards)
        table.removeOne(types, Fk:getCardById(id):getTypeString())
        room:throwCard(id, kl__zhangming.name, data.to, data.to)
      end
    end
    local toObtain = {}
    for _, type_name in ipairs(types) do
      local randomCard = room:getCardsFromPileByRule(".|.|.|.|.|" .. type_name)
      if #randomCard == 0 then
        randomCard = room:getCardsFromPileByRule(".|.|.|.|.|" .. type_name, 1, "discardPile")
      end
      if #randomCard > 0 then
        table.insert(toObtain, randomCard[1])
      end
    end
    if #toObtain > 0 then
      room:moveCardTo(toObtain, Card.PlayerHand, player, fk.ReasonPrey, kl__zhangming.name, nil, false, player, "@@kl__zhangming-inhand-turn")
    end
  end,
})
kl__zhangming:addEffect("maxcards", {
  exclude_from = function(self, player, card)
    return card:getMark("@@kl__zhangming-inhand-turn") > 0
  end,
})

return kl__zhangming
